<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SHOP 管理中心 - 商品分类 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/admin/styles/general.css" rel="stylesheet" type="text/css" />
<link href="/admin/styles/main.css" rel="stylesheet" type="text/css" />
</head>
<style>
  .tr-none{
          display:none;
     }
</style>
<body>

<h1>
<span class="action-span"><a href="/admin/cat_add">添加分类</a></span>
<span class="action-span1">SHOP 管理中心</span><span id="search_id" class="action-span1"> - 商品分类 </span>
<div style="clear:both"></div>
</h1>

<form method="post" action="" name="listForm">
<!-- start ad position list -->
	<div class="list-div" id="listDiv">
		<table width="100%" cellspacing="1" cellpadding="2" id="list-table"  class="table">
			<tbody>
				<tr>
					<th>分类名称</th>
					<th>分类状态</th>
					<th>分类排序</th>
					<th>分类描述</th>
					<th>是否显示</th>
					<th>首页推荐</th>
					<th>排序</th>
					<th>操作</th>
				</tr>
        <?php foreach($res as $k=>$v): ?>
				<tr align="center" class="<?=$v->parent_id !=0 ? 'tr-none' : '' ?>" id="0_1" data-id="<?php echo e($v->cate_id); ?>" data-pid="<?php echo e($v->parent_id); ?>">
					<td align="left" class="first-cell"><?php echo e($v->level); ?>

          <!-- menu_plus.gif -->
						<img src="/admin/images/menu_plus.gif" id="icon_0_1" width="9" height="9" border="0" style="margin-left:0em" class="open-child open-close">
						<span><a href="goods.php?act=list&amp;cat_id=1"><?php echo e($v->cate_name); ?></a></span>
					 </td>
					<td width="10%">
            <?php if($v->cate_status == 1): ?>
            <img src="/admin/images/no.gif" >
            <?php elseif($v->cate_status == 0): ?>
            <img src="/admin/images/yes.gif">
            <?php endif; ?> 
          </td>
					<td width="10%"><input type="text" value="<?php echo e($v->cate_sort); ?>" /></td>
					<td width="10%">
            <?php echo e($v->cate_intro); ?>

          </td>
					<!-- <td width="10%"><img src="/admin/images/yes.gif"></td> -->
					<td>
           <?php if($v->is_show == 1): ?>
            <img src="/admin/images/no.gif" >
            <?php elseif($v->is_show == 0): ?>
            <img src="/admin/images/yes.gif">
            <?php endif; ?> 
          </td>
					<td width="10%" align="center">
            <?php if($v->set_index_recom == 1): ?>
            精品
            <?php elseif($v->set_index_recom == 2): ?>
            最新
            <?php elseif($v->set_index_recom == 3): ?>
            热门
            <?php else: ?>
            未设置
            <?php endif; ?> 
          </td>
					<td width="24%" align="center">
						<!-- <a href="category.php?act=move&amp;cat_id=1">转移商品</a> | -->
						<a href="cat_edit/<?php echo e($v->cate_id); ?>">编辑</a> |
						<a href="cat_del/<?php echo e($v->cate_id); ?>"  title="移除">移除</a>
					</td>
				</tr>
	       <?php endforeach; ?>
  	<!--  end这些代码是显示使用，没有格式化 开发时可删除-->
	</tbody>
  </table>

</div>
</form>



<div id="footer">
	版权所有 &copy; 2006-2013  - NBshop! - </div>
</div>
<script src="<?=URL::asset('/admin/js/jquery.1.12.js')?>"></script>
<script>
 //将子集展开
     $(".table").on('click','.open-child',function(){
          //获取当前分类的主键id
          var id = $(this).parents('tr').data('id');
          //根据id 去查找 pid = id 的 tr
          $("tr[data-pid='"+id+"']").removeClass('tr-none');
          //把当前的展开变成收起
          $(this).attr('src','/admin/images/menu_minus.gif').removeClass('open-child').addClass('close-child');
     })

      //将子集收起
     $(".table").on('click','.close-child',function(){
          //获取当前分类的主键id
          var id = $(this).parents('tr').data('id');
          //把当前的展开变成收起
          $(this).attr('src','/admin/images/menu_plus.gif').removeClass('close-child').addClass('open-child');
          //收起当前分类所有后代分类
          closrChildren(id);
     })
   /**
      * 递归关闭所有后代分类
      * @param    {[type]} pid 
      * @return  {[type]}     
      */
     function closrChildren(pid){
          var child = $('tr[data-pid="'+pid+'"]');
          for(var i=0;i<child.length;i++){
               child.eq(i).addClass('tr-none');//隐藏子集
               //给子集的收起变成展开
               child.eq(i).find('.open-close').text('展开').removeClass('close-child').addClass('open-child');
               //查找当前分类的子集
               var id = child.eq(i).data('id');
               var children = $('tr[data-pid="'+id+'"]');
               if(children.length > 0){
                    closrChildren(id);
               }
          }
     }
</script>
</body>
</html>